<template>
    <div class="zs-table-page-container">
        <div class="zs-card-sm zs-space-bottom zs-layout-flex-row zs-layout-justify-between">
            <span>
                <el-select v-model="companyPlatformId" class="zs-select-md zs-space-right-sm" placeholder="平台商名称"
                    filterable>
                    <el-option v-for="item in platList" :key="item.companyPlatformId" :label="item.companyPlatformName"
                        :value="item.companyPlatformId" />
                </el-select>
                <el-date-picker class="zs-space-right-sm" v-model="startDate" :type="pickerDate" placeholder="月份"
                    :clearable="false" :value-format="valueFormat" :disabled-date="disabledDateStart"
                    @change="getProjectList()" />
                <el-select v-model="projectCode" filterable clearable class="zs-select-md zs-space-right-sm" placeholder="归属项目">
                    <el-option v-for="item in projectList" :key="item.projectCode" :label="item.projectName"
                        :value="item.projectCode" />
                </el-select>
                <el-popover popper-class="zs-popper" placement="bottom-end" trigger="click">
                    <template #reference>
                        <el-button class="zs-btn-square-solid"
                            :class="{ 'zs-btn-square-solid-active': createUser || commodityName || companyServiceName || orderStatus }">
                            <el-icon>
                                <MoreFilled />
                            </el-icon>
                        </el-button>
                    </template>
                    <template #default>
                        <div>
                            <el-input class="zs-select-md zs-space-right-sm" v-model="createUser" placeholder="下单人"
                                clearable />
                            <el-input class="zs-select-md zs-space-right-sm" v-model="commodityName" placeholder="商品名称"
                                clearable />
                            <el-input class="zs-select-md zs-space-right-sm" v-model="companyServiceName" placeholder="服务商"
                                clearable />
                            <el-select v-model="orderStatus" filterable clearable :teleported="false"
                                class="zs-select-md zs-space-right-sm zs-space-top" placeholder="订单状态">
                                <el-option v-for="item in orderStatuList" :key="item.value" :label="item.label"
                                    :value="item.value" />
                            </el-select>
                        </div>
                    </template>
                </el-popover>
                <el-button class="zs-btn-plain" @click="getData()">
                    查询
                </el-button>
            </span>
        </div>
        <div class="zs-card zs-table-page-content">
            <el-table :data="tableData" class="zs-table-page-main" :stripe="stripe">
                <el-table-column label="序号" width="60" :align="'center'">
                    <template #default="scope">
                        {{ scope.$index + 1 + curPageSize * (currentPage - 1) }}
                    </template>
                </el-table-column>
                <el-table-column label="订单编号" :align="'left'" width="120" :show-overflow-tooltip="true">
                    <template #default="scope">
                        {{ scope.row.orderNum }}
                    </template>
                </el-table-column>
                <el-table-column label="归属项目" :align="'left'" :show-overflow-tooltip="true">
                    <template #default="scope">
                        {{ scope.row.projectName }}
                    </template>
                </el-table-column>
                <el-table-column label="下单人" :align="'center'">
                    <template #default="scope">
                        {{ scope.row.createUser }}
                    </template>
                </el-table-column>
                <el-table-column label="商品名称" :align="'left'" :show-overflow-tooltip="true">
                    <template #default="scope">
                        {{ scope.row.commodityName }}
                    </template>
                </el-table-column>
                <el-table-column label="订单金额" :align="'right'">
                    <template #default="scope">
                        {{ toThousands(scope.row.orderPrice) }}
                    </template>
                </el-table-column>
                <el-table-column label="服务商" :align="'left'" :show-overflow-tooltip="true">
                    <template #default="scope">
                        {{ scope.row.companyServiceName }}
                    </template>
                </el-table-column>
                <el-table-column label="订单状态" :align="'center'">
                    <template #default="scope">
                        {{ scope.row.orderStatus == 1 ? '已接单' : scope.row.orderStatus == 2 ? '已结束' : '-' }}
                    </template>
                </el-table-column>
                <el-table-column label="付款金额" :align="'right'">
                    <template #default="scope">
                        {{ toThousands(scope.row.payedPrice) }}
                    </template>
                </el-table-column>
                <el-table-column label="分佣金额" :align="'right'">
                    <template #default="scope">
                        {{ toThousands(scope.row.dividePrice) }}
                    </template>
                </el-table-column>
                <el-table-column label="分佣比例" :align="'right'">
                    <template #default="scope">
                        {{ scope.row.divideRatio == '-' ? '-' : `${scope.row.divideRatio}%` }}
                    </template>
                </el-table-column>
                <el-table-column label="下发金额" :align="'right'">
                    <template #default="scope">
                        {{ toThousands(scope.row.distributePrice) }}
                    </template>
                </el-table-column>
                <el-table-column label="未下发金额" :align="'right'">
                    <template #default="scope">
                        {{ toThousands(scope.row.unDistributePrice) }}
                    </template>
                </el-table-column>
                <el-table-column label="下发比例" :align="'right'">
                    <template #default="scope">
                        {{ scope.row.distributeRatio == '-' ? '-' : `${scope.row.distributeRatio}%` }}
                    </template>
                </el-table-column>
                <el-table-column prop="" label="查看" width="100" :align="'right'">
                    <template #default="scope">
                        <el-button class="zs-link" link size="small" @click="goDetail(scope.row)">付款</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <!-- <div class="zs-text-gray-dark zs-text-sm zs-space-top">*销售额：万元；客流量：万人次；车流量：车次</div> -->
            <div class="zs-space-top-sm zs-table-page-pagination">
                <el-pagination v-model:currentPage="currentPage" v-model:page-size="curPageSize" :page-sizes="curPageSizes"
                    :small="true" :background="true" layout="total, sizes, prev, pager, next, jumper" :total="total"
                    @size-change="handleSizeChange" @current-change="handleCurrentChange" />
            </div>
        </div>
    </div>
</template>
<script setup>
import dashBoardApi from '@/api/EnterpriseServices/dashBoard'
import detailApi from '@/api/EnterpriseServices/detailPages'
import { toThousands } from '@/utils/number-util'
import { ref } from 'vue'
import { useStore } from 'vuex'
import { useRoute, useRouter } from 'vue-router'
const router = useRouter()
let store = useStore()
const stripe = ref(true)
const route = useRoute().query

let companyPlatformId = ref(Number(route.companyPlatformId))
let platList = ref([])

let startDate = ref(route.theDate)
let valueFormat = ref('YYYY-MM')
let pickerDate = ref('month')

let projectCode = ref('')
let projectList = ref([])
let createUser = ref('')
let commodityName = ref('')
let companyServiceName = ref('')

let orderStatus = ref('')
let orderStatuList = ref([{label: '已接单', value: 1}, {label: '已结束', value: 2}])

const tableData = ref([])

const getPlatList = () => {
    dashBoardApi.getCompanyPlatformListApi().then((res) => {
        if (res.data.code == 200) {
            platList.value = res.data.data
        }
    })
}
getPlatList()

const getProjectList = () => {
    detailApi.getOrderPartnerProjectInfosApi({ confirmTime: startDate.value }).then((res) => {
        if (res.data.code == 200) {
            projectList.value = res.data.data
        }
    })
}
getProjectList()

// 分页
const curPageSizes = ref(store.state.uiPageSizes)
let curPageSize = ref(store.state.uiPageSizeDefault)
let currentPage = ref(1)
const total = ref(0)
const handleSizeChange = (val) => {
    curPageSize.value = val
    getList()
}
const handleCurrentChange = (val) => {
    currentPage.value = val
    getList()
}

const getList = () => {
    detailApi.esPortalOrderPartnerDetailApi({ companyPlatformId: companyPlatformId.value, confirmTime: startDate.value, projectCode: projectCode.value, createUser: createUser.value, commodityName: commodityName.value, companyServiceName: companyServiceName.value, orderStatus: orderStatus.value, pageNum: currentPage.value, pageSize: curPageSize.value }).then((res) => {
        if (res.data.code == 200) {
            tableData.value = res.data.data.list
            total.value = res.data.data.total
        }
    })
}
getList()
const getData = () => {
    currentPage.value = 1
    getList()
}

const disabledDateStart = (date) => {
    return date.getTime() > new Date().getTime()
}

const goDetail = (row) => {
    router.push({
        path: '/page/routeController/index',
        query: {
            rid: 'EnterpriseServices/detailPages/partnerAssay/partnerAssayPay',
            rTitle: '付款明细',
            row: JSON.stringify(row)
        },
    })
}

</script>


<style scoped lang="scss"></style>
